

#import "BaseNavigationController.h"
#import "UIColor+Hex.h"
@interface BaseNavigationController () <UITabBarControllerDelegate,UITabBarDelegate>

@end

@implementation BaseNavigationController

- (void)initialize
{
    // 1.设置导航栏主题
    [self setupNavBarTheme];
    // 2.设置导航栏按钮主题
    [self setupBarButtonItemTheme];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 1.设置导航栏主题
    [self setupNavBarTheme];
    // 2.设置导航栏按钮主题
//    [self setupBarButtonItemTheme];
}

/**
 *  设置 导航栏 主题
 */
- (void)setupNavBarTheme
{
    // 取出appearance对象
    UINavigationBar *navBar = self.navigationBar;//[UINavigationBar appearance];
    navBar.translucent = NO;
    // 设置导航栏的被禁颜色属性
    [navBar setTintColor:[UIColor whiteColor]];
    navBar.barTintColor = cCommonRedColor;
    
    // 设置文字的属性
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] =[UIColor whiteColor];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:17.0];
    [navBar setTitleTextAttributes:textAttrs];
    
    // 设置返回按钮
    UIImage *backImage = [UIImage imageNamed:@"p_backArrow"];
//    backImage = [backImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    navBar.backIndicatorImage = backImage;
    navBar.backIndicatorTransitionMaskImage = backImage;
    [navBar setShadowImage:[[UIImage alloc] init]];
    [navBar setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
}

//  设置 （left right）按钮 主题
- (void)setupBarButtonItemTheme
{
    
    UIBarButtonItem * item = [UIBarButtonItem appearance];
    // 设置普通状态
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:15.0];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    // 设置不可用状态
    NSMutableDictionary *disableTextAttrs = [NSMutableDictionary dictionary];
    disableTextAttrs[NSForegroundColorAttributeName] =[UIColor whiteColor];
    disableTextAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:15.0];
    [item setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled];
}

#pragma mark - Push
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
} 


@end
